<?php

declare(strict_types=1);

namespace App\Model;

use Hyperf\DbConnection\Model\Model;

/**
 * 收藏夹模型
 */
class FavoriteFolder extends Model
{
    /**
     * 表名
     */
    protected ?string $table = 'favorite_folder';

    /**
     * 可批量赋值的字段
     */
    protected array $fillable = [
        'user_id',
        'name',
        'is_public'
    ];

    /**
     * 类型转换
     */
    protected array $casts = [
        'is_public' => 'boolean',
        'created_at' => 'datetime',
        'updated_at' => 'datetime',
    ];

    /**
     * 关联用户
     */
    public function user()
    {
        return $this->belongsTo(\App\Model\User::class, 'user_id');
    }

    /**
     * 关联收藏记录
     */
    public function favorites()
    {
        return $this->hasMany(\App\Model\ArticleFavorite::class, 'folder_id');
    }
}